#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	while(cin>>a>>b){
		bool flag = 0;
		for(int i = b;i >= a;i--){
			flag = 0;
			int k = sqrt(i);
			if(i == 1){
				continue;
			}
			for(int j = 2;j <= k;j++){
				if(i%j == 0){
					flag = 1;
					break;
				}
			}
			if(flag){
				continue;
			}

			cout<<i<<endl;
			break;
		}
		if(flag){
			cout<<"0"<<endl;
		}
	}
	return 0;
}
